﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Collections.ObjectModel;
using ScormModel.View;
namespace ScormModel
{
    [Serializable()]
    public class Sequencing
    {
        private string _id;
        private string _identifier;
        private Objectives _Objectives;
        private ObjectivesSeq _ObjectivesSeq;
        private LimitConditions _limitConditions;
        private RollupRules _rollupRules;
        private SequencingRules _sequencingRules;
        private ControlMode _controlMode;
        private RollupConsiderations _rollupConsiderations;
        private RandomizationControls _randomizationControls;
        private DeliveryControls _deliveryControls;
        private ConstrainedChoiceConsiderations _constrainedChoiceConsiderations;
        private bool isChoose;
        private string description;
        private bool isEdited;
        private bool inUse;
        private string sequencingName;
        ObservableCollection<ConditionView> listPreConditionData = new ObservableCollection<ConditionView>();
        ObservableCollection<ConditionActionView> listPreConditionActionData = new ObservableCollection<ConditionActionView>();
        ObservableCollection<ConditionView> listPostConditionData = new ObservableCollection<ConditionView>();
        ObservableCollection<ConditionActionView> listPostConditionActionData = new ObservableCollection<ConditionActionView>();
        ObservableCollection<ConditionView> listExitConditionData = new ObservableCollection<ConditionView>();
        ObservableCollection<ConditionActionView> listExitConditionActionData = new ObservableCollection<ConditionActionView>();
        ObservableCollection<RollUpRuleView> listRollupConditionData = new ObservableCollection<RollUpRuleView>();
        ObservableCollection<ConditionActionView> listRollupConditionActionData = new ObservableCollection<ConditionActionView>();
        [NonSerialized]
        private XmlNode _sequencingContent;
        [XmlAttribute("ID")]
        public string ID
        {
            get { return this._id; }
            set { this._id = value; }
        }
        [XmlAttribute("IDRef")]
        public string Identifier
        {
            get { return this._identifier; }
            set { this._identifier = value; }
        }
        [XmlElement("controlMode", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public ControlMode ControlMode
        {
            get { return this._controlMode; }
            set { this._controlMode = value; }
        }
        [XmlElement("limitConditions", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public LimitConditions LimitConditions
        {
            get { return this._limitConditions; }
            set { this._limitConditions = value; }
        }
        
        [XmlElement("objectives", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public Objectives Objectives
        {
            get { return this._Objectives; }
            set { this._Objectives = value; }
        }
        [XmlElement("objectives", Namespace = "http://www.adlnet.org/xsd/adlseq_v1p3")]
        public ObjectivesSeq ObjectivesSeq
        {
            get { return this._ObjectivesSeq; }
            set { this._ObjectivesSeq = value; }
        }
        [XmlElement("sequencingRules", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public SequencingRules SequencingRules
        {
            get { return this._sequencingRules; }
            set { this._sequencingRules = value; }
        }
        [XmlElement("rollupRules", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public RollupRules RollupRules
        {
            get { return this._rollupRules; }
            set { this._rollupRules = value; }
        }
        [XmlElement("rollupConsiderations", Namespace = "http://www.adlnet.org/xsd/adlseq_v1p3")]
        public RollupConsiderations RollupConsiderations
        {
            get { return this._rollupConsiderations; }
            set { this._rollupConsiderations = value; }
        }
        [XmlElement("randomizationControls", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public RandomizationControls RandomizationControls
        {
            get { return this._randomizationControls; }
            set { this._randomizationControls = value; }
        }
        [XmlElement("deliveryControls", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public DeliveryControls DeliveryControls
        {
            get { return this._deliveryControls; }
            set { this._deliveryControls = value; }
        }
        [XmlElement("constrainedChoiceConsiderations", Namespace = "http://www.adlnet.org/xsd/adlseq_v1p3")]
        public ConstrainedChoiceConsiderations ConstrainedChoiceConsiderations
        {
            get { return this._constrainedChoiceConsiderations; }
            set { this._constrainedChoiceConsiderations = value; }
        }
        
        [XmlIgnoreAttribute]
        public XmlNode SequencingContent
        {
            get { return this._sequencingContent; }
            set { this._sequencingContent = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionView> ListPreConditionData
        {
            get { return this.listPreConditionData; }
            set { this.listPreConditionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionView> ListPostConditionData
        {
            get { return this.listPostConditionData; }
            set { this.listPostConditionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionView> ListExitConditionData
        {
            get { return this.listExitConditionData; }
            set { this.listExitConditionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<RollUpRuleView> ListRollupConditionData
        {
            get { return this.listRollupConditionData; }
            set { this.listRollupConditionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionActionView> ListPreConditionActionData
        {
            get { return this.listPreConditionActionData; }
            set { this.listPreConditionActionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionActionView> ListPostConditionActionData
        {
            get { return this.listPostConditionActionData; }
            set { this.listPostConditionActionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionActionView> ListExitConditionActionData
        {
            get { return this.listExitConditionActionData; }
            set { this.listExitConditionActionData = value; }
        }
        [XmlIgnoreAttribute]
        public ObservableCollection<ConditionActionView> ListRollupConditionActionData
        {
            get { return this.listRollupConditionActionData; }
            set { this.listRollupConditionActionData = value; }
        }
        [XmlIgnoreAttribute]
        public bool IsChoose
        {
            get { return this.isChoose; }
            set { this.isChoose = value; }
        }
        [XmlIgnoreAttribute]
        public string Description
        {
            get { return this.description; }
            set { this.description = value; }
        }
        [XmlIgnoreAttribute]
        public bool IsEdited
        {
            get { return this.isEdited; }
            set { this.isEdited = value; }
        }
        [XmlIgnoreAttribute]
        public string SequencingName
        {
            get { return this.sequencingName; }
            set { this.sequencingName = value; }
        }
        [XmlIgnoreAttribute]
        public bool InUse
        {
            get { return this.inUse; }
            set { this.inUse = value; }
        }
        public void buildSequencing(string courseTemplate)
        {
            XmlElement element = (XmlElement)_sequencingContent;
            //control mode
            if ((element.GetElementsByTagName("imsss:controlMode") != null) && (element.GetElementsByTagName("imsss:controlMode").Count > 0))
            {
                _controlMode = new ControlMode();
                _controlMode.ControlModeContent = (element.GetElementsByTagName("imsss:controlMode"))[0];
                _controlMode.buildControlMode();
            }
            //sequencing rules
            if ((element.GetElementsByTagName("imsss:sequencingRules") != null) && (element.GetElementsByTagName("imsss:sequencingRules").Count > 0))
            {
                _sequencingRules = new SequencingRules();
                _sequencingRules.SequencingRulesContent = (element.GetElementsByTagName("imsss:sequencingRules"))[0];
                _sequencingRules.buildSequencingRules();
            }
            //limit conditions
            if ((element.GetElementsByTagName("imsss:limitConditions") != null) && (element.GetElementsByTagName("imsss:limitConditions").Count > 0))
            {
                _limitConditions = new LimitConditions();
                _limitConditions.LimitConditionsContent = (element.GetElementsByTagName("imsss:limitConditions"))[0];
                _limitConditions.buildLimitConditions();
            }
            //rollupRules
            if ((element.GetElementsByTagName("imsss:rollupRules") != null) && (element.GetElementsByTagName("imsss:rollupRules").Count > 0))
            {
                _rollupRules = new RollupRules();
                _rollupRules.RollupRulesContent = (element.GetElementsByTagName("imsss:rollupRules"))[0];
                _rollupRules.buildRollupRules();
            }
            //Objectives
            if ((element.GetElementsByTagName("imsss:objectives") != null) && (element.GetElementsByTagName("imsss:objectives").Count > 0))
            {
                _Objectives = new Objectives();
                _Objectives.ObjectivesContent = (element.GetElementsByTagName("imsss:objectives"))[0];
                _Objectives.buildObjectives();
            }
            //RadomizationControl
            if ((element.GetElementsByTagName("imsss:randomizationControls") != null) && (element.GetElementsByTagName("imsss:randomizationControls").Count > 0))
            {
                _randomizationControls = new RandomizationControls();
                _randomizationControls.RandomizationControlsContent = (element.GetElementsByTagName("imsss:randomizationControls"))[0];
                _randomizationControls.buildRandomizationControls();
            }
            //DeliveryControls
            if ((element.GetElementsByTagName("imsss:deliveryControls") != null) && (element.GetElementsByTagName("imsss:deliveryControls").Count > 0))
            {
                _deliveryControls = new DeliveryControls();
                _deliveryControls.DeliveryControlsContent = (element.GetElementsByTagName("imsss:deliveryControls"))[0];
                _deliveryControls.buildDeliveryControls();
            }
            //ConstrainedChoiceConsiderations
            if ((element.GetElementsByTagName("adlseq:constrainedChoiceConsiderations") != null) && (element.GetElementsByTagName("adlseq:constrainedChoiceConsiderations").Count > 0))
            {
                _constrainedChoiceConsiderations = new ConstrainedChoiceConsiderations();
                _constrainedChoiceConsiderations.ConstrainedChoiceConsiderationsContent = (element.GetElementsByTagName("adlseq:constrainedChoiceConsiderations"))[0];
                _constrainedChoiceConsiderations.buildConstrainedChoiceConsiderations();
            }
            //RollupConsiderations
            if ((element.GetElementsByTagName("adlseq:rollupConsiderations") != null) && (element.GetElementsByTagName("adlseq:rollupConsiderations").Count > 0))
            {
                _rollupConsiderations = new RollupConsiderations();
                _rollupConsiderations.RollupConsiderationsContent = (element.GetElementsByTagName("adlseq:rollupConsiderations"))[0];
                _rollupConsiderations.buildRollupConsiderations();
            }

        }
    }
}
